package com.itheima.mall.dubbo.api.oms;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.itheima.mall.dubbo.mapper.oms.OrderMapper;
import com.itheima.mall.dubbo.mapper.oms.OrderOperateHistoryMapper;
import com.itheima.mall.entity.domain.oms.Order;
import com.itheima.mall.entity.domain.oms.OrderItem;
import com.itheima.mall.entity.domain.oms.OrderOperateHistory;
import com.itheima.mall.entity.dto.oms.OmsOrderDetail;
import com.itheima.mall.entity.vo.oms.OrderVo;
import com.itheima.mall.entity.vo.oms.ReceiverInfoVo;
import org.apache.dubbo.config.annotation.DubboReference;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;

import java.time.LocalDateTime;
import java.util.Date;
import java.util.List;

/**
 * <p>
 * 订单表 服务实现类
 * </p>
 *
 * @author qinglang
 * @since 2022-07-05
 */

@DubboService
public class OrderImplService extends ServiceImpl<OrderMapper, Order> implements OrderService {

    @Autowired
    private OrderItemService orderItemService;

    @Autowired
    private OrderOperateHistoryService orderOperateHistoryService;


    /**
     * 获取指定订单详情
     * @param id
     * @return
     */
    @Override
    public OmsOrderDetail detail(Long id) {
        OmsOrderDetail omsOrderDetail = new OmsOrderDetail();
        //获取订单表
        Order order = this.getById(id);
        BeanUtils.copyProperties(order, omsOrderDetail);
        //获取历史表
        LambdaQueryWrapper<OrderOperateHistory> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(OrderOperateHistory::getOrderId,id);
        List<OrderOperateHistory> list = orderOperateHistoryService.list(wrapper);
        //获取详细表
        LambdaQueryWrapper<OrderItem> qw = new LambdaQueryWrapper<>();
        qw.eq(OrderItem::getOrderId, id);
        List<OrderItem> list1 = orderItemService.list(qw);

//        BeanUtils.copyProperties(list, omsOrderDetail);
//        BeanUtils.copyProperties(list1, omsOrderDetail);

        omsOrderDetail.setOrderItemList(list1);
        omsOrderDetail.setHistoryList(list);

        return omsOrderDetail;
    }
}
